package com.likersai.funa.service.impl;

import com.likersai.funa.dao.CustomerDao;
import com.likersai.funa.pojo.dto.req.auth.LoginReq;
import com.likersai.funa.pojo.dto.rsp.auth.LoginRsp;
import com.likersai.funa.pojo.entity.Customer;
import com.likersai.funa.service.AuthService;
import com.likersai.funa.util.SecurityUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 权限服务类实现
 *
 * @author sun.ye
 * @since 2021-10-04 16:54
 */
@Slf4j
@Service("authService")
public class AuthServiceImpl implements AuthService {

    @Resource
    private CustomerDao customerDao;

    @Override
    public LoginRsp login (LoginReq loginInfo) {
//        customerDao.queryAll()
        return null;
    }


    private LoginRsp validLogin(LoginReq loginInfo, Customer customer){

        String pwdBase64 = loginInfo.getPassword();
        String login = loginInfo.getLogin();

        String loginPassword = SecurityUtil.decodeBase64(pwdBase64);
        String loginpasswordSha1 = SecurityUtil.getShaSecurity(loginPassword);
//        String userPasswordSha1 = customer.getPassword();

        LoginRsp res = new LoginRsp();
        if(loginpasswordSha1.equals(userPasswordSha1)){
            String token = SecurityUtil.getToken(login);
            res.setCheckResult(true);
            res.setToken(token);
        }else {
            res.setCheckResult(false);
        }
        return res;
    }
}